<!DOCTYPE html>
<html lang="zh">
<head>
<meta charset="utf-8">
<title>内部管理系统</title>
<meta content="IE=edge,chrome=1" http-equiv="X-UA-Compatible">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="">
<meta name="author" content="">

<link rel="stylesheet" type="text/css"
	href="../../lib/bootstrap/css/bootstrap.css">
<link rel="stylesheet" type="text/css"
	href="../../stylesheets/theme.css">
<link rel="stylesheet"
	href="../../lib/font-awesome/css/font-awesome.css">

<script src="../../lib/jquery.min.js" type="text/javascript"></script>
<script src="../../lib/bootstrap/js/bootstrap.js"></script>
<script src="../../lib/jquery.validate.min.js"></script>
<script src="../../lib/jquery.cookie.js"></script>
<script src="../../lib/jquery.messager.js"></script>
<script src="../../js/init.js"></script>

<!-- <script src="../../lib/jquery.min.js" type="text/javascript"></script>
<script src="../../lib/bootstrap/js/bootstrap.js"></script>
<script src="../../lib/jquery.validate.min.js"></script>
<script src="../../lib/jquery.cookie.js"></script>
<script src="../../lib/jquery.form.js"></script>
<script src="../../lib/jquery-1.9.1.js"></script>
<script src="../../lib/ajaxfileupload.js"></script>
<script src="../../lib/jquery.messager.js"></script>
<script src="../../js/init.js"></script>
<link rel="stylesheet" href="//apps.bdimg.com/libs/jqueryui/1.10.4/css/jquery-ui.min.css">
<script src="//apps.bdimg.com/libs/jquery/1.10.2/jquery.min.js"></script>
<script src="//apps.bdimg.com/libs/jqueryui/1.10.4/jquery-ui.min.js"></script> -->

<style type="text/css">
#container {
	height: 300px;
	width: 400px;
}

.fl {
	float: left
}

select {
	width: 130px;
}
.title{
	font-size:18px;
	font-weight:bold;
}
</style>
<!-- Le HTML5 shim, for IE6-8 support of HTML5 elements -->
<!--[if lt IE 9]>
      <script src="lib/html5.js"></script>
    <![endif]-->
</head>

<!--[if lt IE 7 ]> <body class="ie ie6"> <![endif]-->
<!--[if IE 7 ]> <body class="ie ie7 "> <![endif]-->
<!--[if IE 8 ]> <body class="ie ie8 "> <![endif]-->
<!--[if IE 9 ]> <body class="ie ie9 "> <![endif]-->
<!--[if (gt IE 9)|!(IE)]><!-->
<body class="">
	<!--<![endif]-->

	<div class="navbar"></div>
	<div class="common"></div>

	<div class="sidebar-nav"></div>

	<div class="content">
		<div class="well">
			<ul class="nav nav-tabs">
				<li class="active"><a href="#userlist" data-toggle="tab">企业</a></li>
			</ul>
			<div id="myTabContent" class="tab-content">
				<div class="tab-pane active in" id="storelist">

					<div class="container-fluid">
						<div class="span8">
							<form id="submitForm" name="submitForm" class="form-horizontal" enctype="multipart/form-data">
								<div class="control-group title">logo </div>
								<input type=hidden id="companyId" name="companyId">

								<div class="control-group">
									<img alt="logo" src="" id='logo' name='logo' height="136px" width="136px">
									<input type="file" name="upload1" id="upload1" size="16">
									<input type="button" value="上传" id="btn-submit" onclick="uploadFile('upload1', 1)">
									
								</div>
								
								<div class="form-actions">
									<button id="btn-back1" type="button" class="btn ">返回</button>
									<button id="btn-save1" type="button" class="btn ">保存</button>
								</div>
								
								
								<div class="control-group title">photo</div>

								<div class="control-group" id="photo-div">
								</div>
								<div class="control-group">
								
									<input type="file" name="upload2" id="upload2" size="16">
									<input type="button" value="上传" id="btn-submit" onclick="uploadFile('upload2', 2)">
									
								</div>
								
								<div class="form-actions">
									<button id="btn-back2" type="button" class="btn ">返回</button>
									<button id="btn-save2" type="button" class="btn ">保存</button>
								</div>

							</form>
						</div>
					</div>
				</div>
			</div>
		</div>
	</div>


	<script type="text/javascript">
	
		//初始化导航栏
		$(function() {
			initAdminNavBar();
			initCommon();
			initSideBar('user-management', 'company-list');
			reloadTable();
		});
		
		
		
		
		//初始化用户详细信息
		function reloadTable(){
			var companyId = getparastr('companyId');
			$("#companyId").val(companyId);
				$.ajax({
					contentType : "application/json",
					url : api_base_url
							+ "selectCompanyLogo.json?companyId="
							+ companyId,
					dataType : "json",
					success : function(data) {
						if (data.code == "200") {
							var logo = data.responseData.logo;
							$("#logo").attr("src", logo);
							
							var rows = '';
							var photoList = data.responseData.photoList;
							for (var int = 0; int < photoList.length; int++) {
								rows += "<img src='" + photoList[int].photoUrl + "' height='136px' width='136px'>"
										+ "<button  type='button' onclick='delCompanyPhoto("
										+ photoList[int].photoId
										+ ")' class='btn btn-success'>删除</button>";
								rows += "<br>";
							}
							rows += "<img src='' id='tempPhoto' name='tempPhoto' height='136px' width='136px'>"

							$('#photo-div').html(rows);

						}
					}
				
				});
		}

		
		
		//返回
		$('#btn-back1').on('click', function() {
			history.back()
		});
		
		//保存
		$('#btn-save1').on('click', function() {
			var companyId = $('#companyId').val();
			var logo = $("#logo")[0].src; 
			
			$.ajax({
				contentType : "application/json",
				url : api_base_url
						+ "saveCompanyLogo.json?companyId=" + companyId
						+ "&logo=" + logo,
				dataType : "json",
				success : function(data) {
					reloadTable();
					$.messager.anim('fade', 1000);
				    $.messager.show('操作提示',data.msg, 5000);
				}
			});
		});
		//返回
		$('#btn-back2').on('click', function() {
			history.back()
		});
		
		//保存
		$('#btn-save2').on('click', function() {
			var companyId = $('#companyId').val();
			var photo = $("#tempPhoto")[0].src; 
			
			$.ajax({
				contentType : "application/json",
				url : api_base_url
						+ "saveCompanyPhoto.json?companyId=" + companyId
						+ "&photo=" + photo,
				dataType : "json",
				success : function(data) {
					reloadTable();
					$.messager.anim('fade', 1000);
				    $.messager.show('操作提示',data.msg, 5000);
				}
			});
		});

		
		function uploadFile(uploadId, flag){
			var fileObj = document.getElementById(uploadId).files[0]; // 获取文件对象
            var FileController = api_base_url1 + "open/fileUpload.json";                    // 接收上传文件的后台地址 
            var form = new FormData(); // FormData 对象
            form.append("file", fileObj);// 文件对象
            var xhr = new XMLHttpRequest();// XMLHttpRequest 对象
            xhr.open("post", FileController, true);
            xhr.onload = function (data) {
                var responseText = xhr.responseText; 
                var obj = JSON.parse(responseText); 
                var code = obj.code;
                var responseData = obj.responseData;
                if(code == '200'){
                	if(flag == 1){
                		$("#logo").attr("src", responseData);
                	}
                	if(flag == 2){
                    	$("#tempPhoto").attr("src", responseData);
                    }
                }
                $.messager.anim('fade', 1000);
			    $.messager.show('操作提示',obj.msg, 5000);
            };
            xhr.send(form);
		}		
		
		function delCompanyPhoto(companyPhotoId) {
			$.ajax({
				contentType : "application/json",
				url : api_base_url + "delCompanyPhoto.json?" + "companyPhotoId="
						+ companyPhotoId,
				dataType : "json",
				type : "get",
				success : function(data) {
					//alert(data);
					if (data.code == "200") {
						reloadTable();
					}
					$.messager.anim('fade', 1000);
				    $.messager.show('操作提示',data.msg, 5000);
				}
			});
		}
		

	</script>

</body>
</html>


